////////////////////////////////////////////////////////////////////////////////

#ifndef _CLIENTPACKETFACTORY_H_
#include "clientpacketfactory.h"
#endif

////////////////////////////////////////////////////////////////////////////////

#ifndef _SERVERSTATEPACKETONCLIENT_H_
#include "serverstatepacketonclient.h"
#endif

#ifndef _SERVERINFOPACKETONCLIENT_H_
#include "serverinfopacketonclient.h"
#endif

#ifndef _LOADER_H_
#include "loader.h"
#endif

////////////////////////////////////////////////////////////////////////////////


ClientPacketFactory::ClientPacketFactory()
{
}


////////////////////////////////////////////////////////////////////////////////


ServerPacketOnClient* ClientPacketFactory::ComposePacket( Buffer& _buffer )
{
    Packet::PacketCode code;
    _buffer.ReadMemory( &code, sizeof(Packet::PacketCode) );
    Loader loader(_buffer);

    switch (code)
    {
    case Packet::SERVER_STATE:
        {
            ServerStatePacket serverStatePacket = loader.LoadServerStatePacket();
            return new ServerStatePacketOnClient(serverStatePacket);
        }
        
    case Packet::SERVER_INFO:
        {
            ServerInfoPacket serverInfoPacket = loader.LoadServerInfoPacket();
            return new ServerInfoPacketOnClient(serverInfoPacket);
        }

    default:
        throw "not implemented";
    }
}


////////////////////////////////////////////////////////////////////////////////
